package com.hongyi.system.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.hongyi.common.log.annotation.Log;
import com.hongyi.common.web.controller.BaseController;
import com.hongyi.common.framework.domain.JsonResult;
import com.hongyi.common.mybatis.page.PageData;
import com.hongyi.common.mybatis.page.PageQuery;
import com.hongyi.common.log.enums.BusinessType;
import com.hongyi.system.domain.dto.SysNoticeDto;
import com.hongyi.system.domain.vo.SysNoticeVo;
import com.hongyi.system.service.ISysNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.validation.annotation.Validated;
import com.hongyi.common.framework.validate.AddGroup;
import com.hongyi.common.framework.validate.EditGroup;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import com.hongyi.common.framework.utils.common.CollectionUtils;

/**
 * 通知公告
 *
 * @author DingHao
 */
@ApiSort(value = 14)
@Api(tags = "通知公告接口")
@RestController
@RequestMapping("/system/notice")
public class SysNoticeController extends BaseController {

    @Autowired
    ISysNoticeService sysNoticeService;

    /**
     * 查询通知公告分页列表
     * @param sysNoticeDto 通知公告业务对象
     * @return 通知公告分页数据
     */
    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询通知公告分页列表")
    @ApiImplicitParam(name = "sysNotice", value = "通知公告业务对象", paramType = "query", dataTypeClass = SysNoticeDto.class)
    @SaCheckPermission("system:notice:list")
    @GetMapping(value = "/list")
    public PageData<SysNoticeVo> list(SysNoticeDto sysNoticeDto, PageQuery pageQuery) {
        return sysNoticeService.querySysNoticeVoPageList(sysNoticeDto,pageQuery);
    }

    /**
     * 获取通知公告详细信息
     *
     * @param noticeId 通知公告主键
     */
    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "获取通知公告详细信息")
    @ApiImplicitParam(name = "noticeId", value = "通知公告主键", paramType = "path", dataTypeClass = Long.class, required = true)
    @SaCheckPermission("system:notice:query")
    @GetMapping(value = "/{noticeId}")
    public JsonResult<SysNoticeVo> getInfo(@PathVariable("noticeId") Long noticeId) {
        return JsonResult.ok(sysNoticeService.querySysNoticeVoById(noticeId));
    }

    /**
     * 新增通知公告
     *
     *  @param sysNoticeDto 通知公告业务对象
     */
    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增通知公告")
    @SaCheckPermission("system:notice:add")
    @Log(title = "新增通知公告", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public JsonResult<Void> add(@Validated(AddGroup.class) @RequestBody SysNoticeDto sysNoticeDto) {
        return toResult(sysNoticeService.addSysNotice(sysNoticeDto));
    }

    /**
     * 修改通知公告
     *
     * @param  sysNoticeDto 通知公告业务对象
     */
    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "修改通知公告")
    @SaCheckPermission("system:notice:edit")
    @Log(title = "修改通知公告", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/edit")
    public JsonResult<Void> edit(@Validated(EditGroup.class) @RequestBody SysNoticeDto sysNoticeDto) {
        return toResult(sysNoticeService.editSysNotice(sysNoticeDto));
    }

    /**
     * 删除通知公告
     *
     * @param noticeIds
     */
    @ApiOperationSupport(order = 5)
    @ApiOperation(value = "删除通知公告")
    @ApiImplicitParam(name = "noticeIds", value = "通知公告主键数组", paramType = "path", dataTypeClass = Long.class, allowMultiple = true, required = true)
    @SaCheckPermission("system:notice:remove")
    @Log(title = "删除通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/{noticeIds}")
    public JsonResult<Void> remove(@PathVariable Long[] noticeIds) {
        return toResult(sysNoticeService.removeSysNoticeByIds(CollectionUtils.newArrayList(noticeIds)));
    }

}
